package com.renzhebiao.lkang.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.plugins.Page;
import com.renzhebiao.lkang.base.BaseService;
import com.renzhebiao.lkang.entity.OpusPO;
import com.renzhebiao.lkang.mapper.OpusMapper;
import com.renzhebiao.lkang.page.PageDTO;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.OpusQuery;
import com.renzhebiao.lkang.request.RequestCache;
import com.renzhebiao.lkang.service.IOpusService;
import com.renzhebiao.lkang.utils.BeanCopys;

/**
 * <p>
 * 作品表 服务实现类
 * </p>
 *
 * @author renzhebiao123
 * @since 2018-10-23
 */
@Service
public class OpusService extends BaseService<OpusPO> implements IOpusService {

    @Autowired
    OpusMapper opusMapper;

    @Override
    public void add(OpusPO po) {
        po.allEx(RequestCache.userId());
        this.opusMapper.insert(po);
    }

    @Override
    public void edit(OpusPO po) {
        po.updated(RequestCache.userId());
        this.opusMapper.updateById(po);
    }

    @Override
    public void delete(Long id) {
        this.deleteByLogic(id, OpusPO.class);
    }

    @Override
    public List<OpusPO> getOpusList(OpusQuery po) {

        return this.opusMapper.selectByMap(BeanCopys.toMap(po));
    }

    @Override
    public OpusPO getOpus(Long id) {

        return this.opusMapper.selectById(id);
    }

    @Override
    public PageDTO<OpusPO> getOpusByPage(PaginationDTO<OpusQuery, Void> paging) {

        Page<OpusPO> page = this.getPage(paging);
        List<OpusPO> pos = this.opusMapper.getOpusByPage(page, page.getCondition());
        return this.getPage(page, pos);
    }

}
